//
//  BGActionSheet.m
//  bingke
//
//  Created by zhangkt zhangkt on 12-10-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BGActionSheet.h"

@implementation BGActionSheet
@synthesize m_SharedView;
@synthesize m_SelectView;
@synthesize buttonTitle;
@synthesize delegate;
@synthesize informationText;
@synthesize imageView;

- (id) init
{
    if (self = [super init]) 
    {
        m_SharedView.hidden = YES;
        m_SelectView.hidden = NO;
        isTrue = YES;
        //UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    }
    return self;
}

- (IBAction)xinlang:(id)sender 
{
    NSLog(@"xinglang");
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至新浪微博" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text); 

}

- (IBAction)tengxun:(id)sender 
{
    NSLog(@"tengxun");
    
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至腾讯" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text);
}

- (IBAction)qqZone:(id)sender 
{
     NSLog(@"qqZone");
    
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至QQ空间" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text);
}

- (IBAction)renButton:(id)sender 
{
    NSLog(@"renButton");
    
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至人人" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text);
}

- (IBAction)faceBook:(id)sender 
{
    NSLog(@"faceBook");
    
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至FaceBook" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text);
}

- (IBAction)cancel:(id)sender 
{
    [UIView animateWithDuration:0.5 delay:0 options:0 animations:^() 
    {
        self.frame = CGRectMake(0, 460, 320, 180);
    } completion:^(BOOL finished) 
    {
        [delegate changeBool];
    }];
}

- (IBAction)backButton:(id)sender 
{
    self.m_SelectView.hidden = NO;
    self.m_SharedView.hidden = YES;
}

- (IBAction)startShared:(id)sender 
{
    if([buttonTitle.titleLabel.text isEqualToString:@"分享至腾讯"])
    {
        if(!isTrue)
        {
            [[WBShareKit mainShare] setDelegate:self];
            [[WBShareKit mainShare] startTxOauthWithSelector:@selector(txSuccess:) withFailedSelector:@selector(txError:)];
            isTrue = !isTrue;
            
            NSLog(@"informationText = %@",informationText.text);
        }
        else
        {
            [[WBShareKit mainShare] sendTxRecordWithStatus:@"《倾城之泪》测试" lat:0 lng:0 format:@"json" delegate:self successSelector:@selector(sendRecordTicket:finishedWithData:) failSelector:@selector(sendRecordTicket:failedWithError:)];
//            
//            [[WBShareKit mainShare] sendTxRecordWithStatus:@"《倾城之泪》剧照测试" lat:0 lng:0 format:@"json" path:[[NSBundle mainBundle] pathForResource:@"WBShareKit" ofType:@"png"] delegate:self successSelector:@selector(sendRecordTicket:finishedWithData:) failSelector:@selector(sendRecordTicket:failedWithError:)];
        }
       
    }
    else if([buttonTitle.titleLabel.text isEqualToString:@"分享至新浪微博"])
    {
        
    }
    else if([buttonTitle.titleLabel.text isEqualToString:@"分享至QQ空间"])
    {
        
    }
    else if([buttonTitle.titleLabel.text isEqualToString:@"分享至人人"])
    {
        
    }
    else if([buttonTitle.titleLabel.text isEqualToString:@"分享至FaceBook"])
    {
        
    }
    else if([buttonTitle.titleLabel.text isEqualToString:@"分享至开心网"])
    {
        
    }
}


- (IBAction)StartTXWeibo:(id)sender 
{
    [[WBShareKit mainShare] sendTxRecordWithStatus:@"《倾城之泪》测试" lat:0 lng:0 format:@"json" delegate:self successSelector:@selector(sendRecordTicket:finishedWithData:) failSelector:@selector(sendRecordTicket:failedWithError:)];
}

- (IBAction)StartTXPhotoWeibo:(id)sender 
{
    [[WBShareKit mainShare] sendTxRecordWithStatus:@"《倾城之泪》剧照测试" lat:0 lng:0 format:@"json" path:[[NSBundle mainBundle] pathForResource:@"WBShareKit" ofType:@"png"] delegate:self successSelector:@selector(sendRecordTicket:finishedWithData:) failSelector:@selector(sendRecordTicket:failedWithError:)];
}

#pragma mark tx delegate
- (void)txSuccess:(NSData *)_data
{
    NSLog(@"tx ok:%@",_data);
}

- (void)txError:(NSError *)_error
{
    NSLog(@"tx error:%@",_error);
}

- (void)sendRecordTicket:(OAServiceTicket *)ticket finishedWithData:(NSMutableData *)data
{
    NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"发送腾讯成功" message:string delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [al show];
    [al release];
    
}
- (void)sendRecordTicket:(OAServiceTicket *)ticket failedWithError:(NSError *)error
{
    NSLog(@"error = %@",error);
}



- (IBAction)kaixinwang:(id)sender 
{
    NSLog(@"kaixinwang");
    
    m_SharedView.hidden = NO;
    m_SelectView.hidden = YES;
    [self.buttonTitle setTitle:@"分享至开心网" forState:UIControlStateNormal];
    NSLog(@"buttonTitle = %@",[self.buttonTitle titleLabel].text);
}

- (void)dealloc 
{
    [m_SharedView release];
    [m_SelectView release];
    [buttonTitle release];
    [informationText release];
    [imageView release];
    [super dealloc];
}

@end
